﻿using System;
using Quicklight.Web.Commands;
using Quicklight.Web.Html;
using System.Html;

namespace Quicklight.Web.Razor {

   /// <summary>
   /// Does the binding on behalf of a declarative binding of a ICommand to an event of an element
   /// </summary>
   public class CommandBinder : EventBinder {
      private ICommand command;

      /// <summary>
      /// Constructs a CommandBinder for binding the ICommand to the event of an element 
      /// </summary>
      /// <param name="eventName">Name of the event to bind to</param>
      /// <param name="command">ICommand that must be bound to the event</param>
      public CommandBinder(string eventName, ICommand command)
         : base(eventName) {
         this.command = command;
      }

      /// <summary>
      /// Bind method does the actual binding of the ICommand to the event of the specified element
      /// </summary>
      /// <param name="element">Element with which the binding must occur</param>
      protected override void Bind(Element element) {
         element.Bind(eventName, command);
      }
   }
}
